﻿using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
namespace TK.Game
{
    /// <summary>
    /// 
    /// </summary>
    public class GameStart : MonoBehaviour
    {
        private Button _existButton;
        private Button _newGameButton;
        private Button _loadGameButton;
        private Text _versionText;
        private Canvas root;

        private void Awake()
        {
            root = FindObjectOfType<Canvas>();
            Button[] buttons = root.GetComponentsInChildren<Button>();
            _newGameButton = buttons[0];
            _loadGameButton = buttons[1];
            _existButton = buttons[2];
            _versionText = GameObject.Find("AppVersionText").GetComponent<Text>();
        }

        private void Start()
        {
            // 注册点击事件
            _newGameButton.onClick.AddListener(startGame);
            _loadGameButton.onClick.AddListener(loadGame);
            _existButton.onClick.AddListener(existGame);

            // 显示版本信息
            _versionText.text = "v " + Application.version;
        }


        private void startGame()
        {
            SceneManager.LoadScene(1);
        }

        private void loadGame()
        {

        }

        private void existGame()
        {
            Application.Quit();
        }
    }
}

